package com.evan.review.architecture.components;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.navigation.NavController;
import androidx.navigation.fragment.NavHostFragment;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import com.evan.review.R;
import com.google.android.material.bottomnavigation.BottomNavigationView;

/**
 * Navigation示例Activity
 * 展示Navigation组件的基本用法
 */
public class NavigationExampleActivity extends AppCompatActivity {
    
    private NavController navController;
    private AppBarConfiguration appBarConfiguration;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_navigation_example);
        
        // 设置Toolbar
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        
        // 设置标题
        setTitle("Navigation示例");
        
        // 设置底部导航
        setupBottomNavigation();
    }
    
    /**
     * 设置底部导航
     */
    private void setupBottomNavigation() {
        // 获取NavHostFragment
        NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager()
                .findFragmentById(R.id.nav_host_fragment);
        
        if (navHostFragment != null) {
            // 获取NavController
            navController = navHostFragment.getNavController();
            
            // 设置底部导航
            BottomNavigationView bottomNav = findViewById(R.id.bottom_nav);
            NavigationUI.setupWithNavController(bottomNav, navController);
            
            // 设置ActionBar与Navigation的联动
            appBarConfiguration = new AppBarConfiguration.Builder(
                    R.id.homeFragment, R.id.dashboardFragment, R.id.notificationsFragment)
                    .build();
            NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
        }
    }
    
    /**
     * 处理向上导航
     */
    @Override
    public boolean onSupportNavigateUp() {
        return NavigationUI.navigateUp(navController, appBarConfiguration)
                || super.onSupportNavigateUp();
    }
} 